package com.abel.bigwater.wflow

import org.junit.Assert.*
import org.junit.Test
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.GeometryCollection
import org.locationtech.jts.geom.GeometryFactory
import org.locationtech.jts.io.WKTReader
import org.locationtech.jts.io.WKTWriter
import org.slf4j.LoggerFactory

class LossMngControllerTest {
    @Test
    fun testLoc() {
        val gf = GeometryFactory()
        val gc = gf.createGeometryCollection(arrayOf(
                gf.createPoint(Coordinate(114.0, 23.0)),
                gf.createPoint(Coordinate(115.0, 22.0)),
                gf.createPoint(Coordinate(113.0, 23.0))
        ))

        val wkt = WKTWriter().write(gc)
        lgr.info("wkt for geomcollection: $wkt")
    }

    @Test
    fun testLocAddPoint() {
        val wkt = "GEOMETRYCOLLECTION (POINT (114 23), POINT (115 22), POINT (113 23))"
        val gf = GeometryFactory()
        val gc = WKTReader().read(wkt) as GeometryCollection

        val gc2 = WKTReader().read("GEOMETRYCOLLECTION (POINT (116.1 23.2))") as GeometryCollection

        val gclist = arrayListOf<Geometry>()
        for (i in 1..gc.numPoints) {
            gclist.add(gc.getGeometryN(i - 1))
        }
        for (i in 1..gc2.numPoints) {
            gclist.add(gc2.getGeometryN(i - 1))
        }

        val gc3 = gf.createGeometryCollection(gclist.toTypedArray())
        val wkt2 = WKTWriter().write(gc3)
        lgr.info("union geomcollection: $wkt2")
    }

    @Test
    fun testPoint() {
        val gf = GeometryFactory()
        val wkt = WKTWriter().write(gf.createPoint(Coordinate(112.1, 35.6)))
        lgr.info("pt: $wkt")
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(LossMngControllerTest::class.java)
    }
}